
package com.eyedog.uilibrary.lists;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.eyedog.library.base.BaseFragment;
import com.eyedog.uilibrary.R;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

/**
 * created by jw200 at 2019/3/29 14:19
 **/
public abstract class BaseListFragment extends BaseFragment {

    protected XRecyclerView recyclerView;

    protected ImageView ivAdv;

    protected int mCurrentPage = 1;

    protected EditText etSearch;

    protected TextView tvSearch;

    protected View searchView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View layout = inflater.inflate(R.layout.fragment_list, null, false);
        return layout;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        searchView = view.findViewById(R.id.fl_search);
        etSearch = (EditText) view.findViewById(R.id.et_search);
        Bundle data = getArguments();
        if (data.getBoolean("ISVideoListActivity")) {
            searchView.setVisibility(View.GONE);
        }
        tvSearch = (TextView) view.findViewById(R.id.tv_search);
        ivAdv = (ImageView) view.findViewById(R.id.iv_video_headeradv);
        recyclerView = (XRecyclerView) view.findViewById(R.id.recycler_list);
        recyclerView.setRefreshProgressStyle(ProgressStyle.LineScale);
        recyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
        recyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
        recyclerView.getDefaultRefreshHeaderView().setRefreshTimeVisible(true);
        recyclerView.getDefaultFootView().setLoadingHint("加载中");
        recyclerView.getDefaultFootView().setNoMoreHint("加载完毕");
        recyclerView.getDefaultFootView().setPadding(30, 30, 30, 30);
        recyclerView.setLimitNumberToCallLoadMore(1);

        recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                mCurrentPage = 1;
                BaseListFragment.this.onRefresh();
            }

            @Override
            public void onLoadMore() {
                mCurrentPage++;
                BaseListFragment.this.onLoadMore();
            }
        });
        onRecyclerCreated(recyclerView);
    }

    public void showAdvHeader() {

    }

    protected abstract void onRefresh();

    protected abstract void onLoadMore();

    protected abstract void onRecyclerCreated(RecyclerView recyclerView);
}
